import models from '../../../models'
import bcrypt from 'bcrypt'

export default defineEventHandler(async (event: any) => {
  try {
    const body = await readBody(event)
    const { email, password } = body

    const hashedPassword = await bcrypt.hash(password, 10)
    
    const user = await models.User.create({
      email,
      password: hashedPassword
    })
    
    return {
      success: true,
      user: {
        id: user.id,
        email: user.email
      }
    }
  } catch (error) {
    throw createError({
      statusCode: 500,
      message: '创建用户失败'
    })
  }
}) 